#pragma once

class Room;
class GameSimulator;
class GameManager
{
public:
	GameManager();
	~GameManager();

public:
	void update(UInt32);

public:
	bool createRoom(Player *, UInt32, UInt32, UInt32, UInt8, UInt8, UInt8, UInt8, UInt8);
	UInt8 tryJoinRoom(Player *, UInt32, UInt32);
	UInt8 joinRoom(Player *, UInt32);

	bool testStart(Room *);
	void startGame(Room *);

public:
	UInt32 genRoomID();
	Room * getRoom(UInt32);
	void emptyRoom(UInt32);
	void addRoom(Room *);

	bool dismissRoomImpl(UInt32);

	void addDismissRoom(UInt32);
	bool acceptDismissRoom(Player *, UInt32, UInt8);

	UInt32 getDismissTime(UInt32);

public:
	GameSimulator * getGameSimulator(UInt32);
	void removeGameSimulator(UInt32);
	void testDestroyRoom(UInt32);
	bool testDismissRoomWithoutDestroy(Room *);
	void removeDismissRoom(UInt32);

	void syncHallDestroyRoom(UInt32, UInt64, bool = false);
	std::vector<UInt32> getRids()	{ return _rids; }

	UInt32 getRoomCount() { return static_cast<UInt32>(_gss.size()); }

public:
	void setPlayerDealSeq(UInt64, UInt32);
	UInt32 getPlayerDealSeq(UInt64);
	void delPlayerDealSeq(UInt64);

private:
	std::map<UInt64, UInt32> _playerDealSeqs;

private:
	std::vector<UInt32> _rids;	//for load player
	//std::vector<Room *> _rooms;	//100000 -- 999999 ( 0 -- 899999 )
	std::map<UInt32, Room *> _rooms;
	std::map<UInt32, GameSimulator *> _gss;	//rid ->

private:
	UInt32 _roomCount;
	std::map<UInt32, UInt32> _dismissRooms;
};
